<?php
/**
 * author:歪妻
 * Date: 2020/11/2 0002
 */

require_once 'lib/common.php';
//接收index_1_1.php传过来的id
if (isset($_GET['post_id'])){
    $postId = $_GET['post_id'];
}else{
    //总是定义一个id
    $postId = 0;
}

$pdo = getPDO();

$stmt = $pdo->prepare(
    'SELECT
        title, created_at, body
    FROM
        post
    WHERE
        id = :id'
);
if ($stmt === false)
{
    throw new Exception('准备此查询时出现问题');
}
$result = $stmt->execute(
    array( 'id'=> $postId,)
);
if ($result === false)
{
    throw new Exception('运行此查询时出现问题');
}
$row = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
    <title>
        A blog application |
        <?php echo htmlEscape($row['title']) ?>
    </title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<?php require 'templates/title.php' ?>

<h2>
    <?php echo htmlEscape($row['title']) ?>
</h2>
<div>
    <?php echo $row['created_at'] ?>
</div>
<p>
    <?php echo htmlEscape($row['body']) ?>

</p>
</body>
</html>